<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Cropper.js</title>
    <link rel="stylesheet" href="../lib/crop/cropper.css">
    <style>
        .container {
            max-width: 640px;
            margin: 20px auto;
        }

        img {
            max-width: 100%;
        }
    </style>
</head>
<body>
<div class="container">
    <div>
        <img id="image">
    </div>
</div>
<div>
    <input type="file" id="file">
</div>
<div id="crop">crop</div>
<img id="img">
<script src="../lib/crop/cropper.js"></script>
<script src="../lib/jquery/jquery-1.11.0.js"></script>
<script>
    function getCrop() {
        var image = document.querySelector('#image');
        var minAspectRatio = 0.5;
        var maxAspectRatio = 1.5;
        var cropper = new Cropper(image, {
            aspectRatio: 1/1,
            viewMode: 1,
            ready: function () {
                croppable = true;
            },
            zoomable:true,
            cropBoxMovable:true,
            autoCrop:true,
            toggleDragModeOnDblclick:true,
            background:true
        });
        var croppedCanvas;
        var crop=document.getElementById('crop');
        crop.onclick=function(){
            croppedCanvas = cropper.getCroppedCanvas();
            var src= croppedCanvas.toDataURL();
            document.getElementById('img').setAttribute('src',src);
        }
    }

    $('#file').change(function () {
        console.log(this.files);
        var file=this.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            var result = this.result;
            $('#image').attr('src',result);
            getCrop()
        }

    })


</script>
</body>
</html>
